package com.pzhu.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzhu.dormitory.dao.RoleDao;
import com.pzhu.dormitory.entity.RoleEntity;
import com.pzhu.dormitory.service.RoleService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleDao, RoleEntity> implements RoleService {

    @Override
    public PageUtils<RoleEntity> queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<RoleEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        String name = (String) params.get("name");
        String status = (String) params.get("status");
        if (StringUtils.isNotBlank(name)) {
            lambdaQueryWrapper.like(RoleEntity::getName, "%" + name + "%");
        }
        if (StringUtils.isNotBlank(status)) {
            lambdaQueryWrapper.eq(RoleEntity::getStatus, status);
        }
        IPage<RoleEntity> page = this.page(
                new Query<RoleEntity>().getPage(params),
                lambdaQueryWrapper
        );
        return new PageUtils<>(page);
    }

}
